<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // ** 2. 两个数组， 最终输出：['员工张三，29岁，工作于百度', '员工李四，26岁，工作于阿里巴巴'，...] **

        var employees = [{
            name: '张三', // 员工名字
            empId: 0, // 员工id
            age: 29, // 员工年龄
            compId: 1 // 所属公司id
        }, {
            name: '李四',
            empId: 1,
            age: 26,
            compId: 2
        }, {
            name: '王五',
            empId: 2,
            age: 28,
            compId: 1
        }, {
            name: '小明',
            empId: 3,
            age: 32,
            compId: 3
        }];

        var companies = [{
            name: '百度', // 公司名称
            id: 1 // 公司id
        }, {
            name: '阿里巴巴',
            id: 2
        }, {
            name: '腾讯',
            id: 3
        }];

        var comObj = {} //公司数组转成对象
        companies.forEach(item => {
            comObj[item.id] = item.name
        })

        let newArr = employees.map(item => {
            return `员工${item.name}，${item.age}岁，工作于${comObj[item.compId]}`
        })
        console.log(newArr)
    </script>
</body>

</html>